import { Component, OnInit, Input } from '@angular/core';
import { User } from '../user';
import { FormGroup } from '@angular/forms';
import { from } from 'rxjs';

@Component({
  selector: 'app-dynamic-user',
  templateUrl: './dynamic-user.component.html',
  styleUrls: ['./dynamic-user.component.css']
})
export class DynamicUserComponent implements OnInit {

  @Input() user: User;
  @Input() form: FormGroup;
  constructor() { }

  ngOnInit() {
  }
  get isValid() {
    const nameModel = this.form.controls[this.user.name];
    return nameModel.valid;
  }
  get isDirty() {
    const nameModel = this.form.controls[this.user.name];
    return nameModel.dirty;
  }
  get isTouched() {
    const nameModel = this.form.controls[this.user.name];
    return nameModel.touched;
  }
  get error() {
    const nameModel = this.form.controls[this.user.name];
    return nameModel.errors;
  }
}
